<?php
include 'logincheck.php';
nologin();
if (!empty($_GET['id'])) {
    $id =$_GET['id'];
    include 'conn.php';
    $sql ="select user_id from article where id=?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("i",$id);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();

    if($row['user_id']==$_SESSION['id'] or $_SESSION['level']==='0'){
        $sql = "DELETE FROM article WHERE id = ?";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("i",$id);
        if ($stmt->execute() === true) {
            header('Location: login.php');
            $stmt->close();
            $conn->close();
        } else {
            echo "<script>alert('删除失败，请联系管理员')</script>";
            header('Location: login.php');
            $stmt->close();
            $conn->close();
        }
    }else{
        echo "<script>alert('文章不存在或权限不足')</script>";
    }

}
